set.seed(12345)

# set parameter values for default
l <- .5
c <- 5
uab <- 2
sab <- .5
ue <- 1
se <- .125
ni <- 5
no <-5

diff <-rep(NA,100000)

for (i in 1:100000){

abi <- rlnorm(ni,uab,sab)
abo <- rlnorm(no,uab,sab)
ei <-rlnorm(ni,ue,se)
ist <- which.max(ei+abi)
jst <- which.max(c(abi,abo))
ai <- ei+abi
lenalph <- length(ai)
lxalph2 <- (1-l)*sort(ai,partial=lenalph-1)[lenalph-1]

dif <- abi[ist]-(c(abi,abo)[jst])-c

diff[i] <- dif
}

deltadef <- mean(diff)
deltadef

######################################################
# small i

l <- .5
c <- 5
uab <- 2
sab <- .5
ue <- 1
se <- .125
ni <- 5
no <- 15

diff <-rep(NA,100000)

for (i in 1:100000){

abi <- rlnorm(ni,uab,sab)
abo <- rlnorm(no,uab,sab)
ei <-rlnorm(ni,ue,se)
ist <- which.max(ei+abi)
jst <- which.max(c(abi,abo))
ai <- ei+abi
lenalph <- length(ai)
lxalph2 <- (1-l)*sort(ai,partial=lenalph-1)[lenalph-1]

dif <- abi[ist]-(c(abi,abo)[jst])-c

diff[i] <- dif
}


deltasmi <- mean(diff)
deltasmi

########################################
# low ext
l <- .5
c <- 5
uab <- 2
sab <- .5
ue <- .5
se <- .125
ni <- 5
no <-5

diff <-rep(NA,100000)

for (i in 1:100000){

abi <- rlnorm(ni,uab,sab)
abo <- rlnorm(no,uab,sab)
ei <-rlnorm(ni,ue,se)
ist <- which.max(ei+abi)
jst <- which.max(c(abi,abo))
ai <- ei+abi
lenalph <- length(ai)
lxalph2 <- (1-l)*sort(ai,partial=lenalph-1)[lenalph-1]

dif <- abi[ist]-(c(abi,abo)[jst])-c

diff[i] <- dif
}


deltalowe <- mean(diff)
deltalowe

################################
# high var in skill
l <- .5
c <- 5
uab <- 2
sab <- 1
ue <- 1
se <- .125
ni <- 5
no <-5

diff <-rep(NA,100000)

for (i in 1:100000){

abi <- rlnorm(ni,uab,sab)
abo <- rlnorm(no,uab,sab)
ei <-rlnorm(ni,ue,se)
ist <- which.max(ei+abi)
jst <- which.max(c(abi,abo))
ai <- ei+abi
lenalph <- length(ai)
lxalph2 <- (1-l)*sort(ai,partial=lenalph-1)[lenalph-1]

dif <- abi[ist]-(c(abi,abo)[jst])-c

diff[i] <- dif
}


deltahvar <- mean(diff)
deltahvar

########################################################################

